from code_python.offer.solution_06.ListNode import ListNode


class solution_06:
    def reversePrint(self, head: ListNode) -> list[int]:
        stack = []
        while head:
            stack.append(head.val)
            head = head.next
        #     利用切片，直接倒序
        return stack[::-1]

    @staticmethod
    def reversePrint2(self, head: ListNode) -> list[int]:
        # if not head :
        #     return self.reversePrint2(head.next) + [head.val]
        # else:
        #     return []
        return self.reversePrint2(head.next) + [head.val] if head else []
